import base64
 
import qrcode
import io
 
 
def to_image( url):
    img = qrcode.make(url)
    img = img.get_image()
    in_mem_file = io.BytesIO()
    img.save(in_mem_file, format="PNG")
    in_mem_file.seek(0)
    img_bytes = in_mem_file.read()
    base64_encoded_result_bytes = base64.b64encode(img_bytes)
    base64_encoded_result_str = base64_encoded_result_bytes.decode('ascii')
    # print(base64_encoded_result_str)
    full_pr_code = 'data:image/png;base64,' +base64_encoded_result_str # 这里的png或其他格式可自定义
    print(full_pr_code)
    return full_pr_code
 

to_image('weixin://wxpay/bizpayurl?pr=szIyqLmzz')
